import { Component, OnInit } from '@angular/core';
import { RECHARGE_APPLICATION_OPTION } from '../../../constant/dictionary';
import { AgentService } from '@core/routes-services/agent.service';
import { NzMessageService } from 'ng-zorro-antd';
import { AgentLevelService } from '@core/routes-services/agent-level.service';

@Component({
  selector: 'app-recharge-application',
  templateUrl: './recharge-application.component.html',
})
export class RechargeApplicationComponent implements OnInit {

  statusOptions: any [] = RECHARGE_APPLICATION_OPTION;
  status: any = 1;
  isLoading = false;

  allAgent: any [] = [];
  levelOptions: any [] = [];

  constructor(private message: NzMessageService,
              private agentLevelService: AgentLevelService,
              private agentService:AgentService) {
  }

  ngOnInit(): void {
    this.initAllAgent();
    this.initLevelOptions();
  }

  initAllAgent(){
    this.isLoading = true;
    this.agentService.getAll().then((res) => {
      if (res.status.toString().startsWith("20")) {
        this.allAgent = res.data.agents;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error)
      this.isLoading = false;
    });
  }

  initLevelOptions() {
    this.isLoading = true;
    this.agentLevelService.getAll().then((res) => {
      if (res.status.toString().startsWith('20')) {
        this.levelOptions = res.data.agentLevelsList;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error);
      this.isLoading = false;
    });
  }

  reSearch(e){
    console.log(e)
  }
}
